﻿using System;
using System.Collections.Generic;
using System.Text;
using JEng_Mark_1.Interfaces;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using JEng_Mark_1.Managers;

namespace JEng_Mark_1.Textures
{
    public class JTNoise : JProceduralTexture
    {
        /// <summary>
        /// Construct a new perlin noise texture
        /// </summary>
        /// <param name="width">Width of resulting generated texture</param>
        /// <param name="height">Height of resulting generated texture</param>
        public JTNoise(int width,int height){
            _texWidth = width;
            _texHeight = height;
        }

        /// <summary>
        /// Generate the texture
        /// </summary>
        public override void LoadContent()
        {
            //generate texture
            Random rand = new Random();
            Color[] noisyColors = new Color[_texWidth * _texHeight];
            for (int x = 0; x < _texWidth; x++)
            {
                for (int y = 0; y < _texHeight; y++)
                {
                    float cVal = (float)rand.Next(1000) / 1000.0f;
                    noisyColors[x + (y * _texWidth)] = new Color(cVal, cVal, cVal);
                }
            }
            //set color values
            Texture2D noiseImage = new Texture2D(JEngineManager.Device, _texWidth, _texHeight, 1, TextureUsage.None, SurfaceFormat.Color);
            noiseImage.SetData<Color>(noisyColors);
            _tex = noiseImage;

            _readyToRender = true;
        }

        public override void UnloadContent()
        {
        }
    }
}
